package com.java.activiti.controller;

import java.util.zip.ZipInputStream;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.RepositoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import com.java.activiti.util.ResponseUtil;

import net.sf.json.JSONObject;
@Controller
@RequestMapping("/Deploy")
public class DeployController {
	
	@Resource
	private RepositoryService repositoryService;
	/**
	 * 添上传流程部署ZIP文件
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/addDeploy")
	public String addDeploy(HttpServletResponse response,MultipartFile deployFile) throws Exception{
		repositoryService.createDeployment() //创建部署
		.name(deployFile.getOriginalFilename())	//需要部署流程名称
		.addZipInputStream(new ZipInputStream(deployFile.getInputStream()))//添加ZIP输入流
		.deploy();//开始部署
		JSONObject result=new JSONObject();
		result.put("success", true);
		ResponseUtil.write(response, result);
		return null;
	}
}
